﻿@inject SynthesizerService SynthesizerService

<div class="row">
    <div class="col-12 col-sm-6">
        <Textarea @bind-Value="InputText" rows="6" />
    </div>
    <div class="col-12 col-sm-6 text-center">
        <SpeechWave Show="Start" ShowUsedTime="false" class="my-3" />
        <Button Text="@ButtonText" OnClick="OnStart" Icon="fa-fw fa-solid fa-microphone" />
    </div>
</div>

@code {
    private bool Start { get; set; }

    private string? InputText { get; set; }

    private string ButtonText { get; set; } = "开始合成";

    private async Task OnStart()
    {
        if (ButtonText == "开始合成")
        {
            if (!string.IsNullOrEmpty(InputText))
            {
                await SynthesizerService.SynthesizerOnceAsync(InputText, Synthesizer);
            }
        }
        else
        {
            await SynthesizerService.CloseAsync(Synthesizer);
        }
    }

    private Task Synthesizer(SynthesizerStatus status)
    {
        if (status == SynthesizerStatus.Synthesizer)
        {
            Start = true;
            ButtonText = "停止合成";
        }
        else
        {
            Start = false;
            ButtonText = "开始合成";
        }
        StateHasChanged();
        return Task.CompletedTask;
    }
}
